package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.service.FileControlService;
import com.amsp.oa.oademo.vo.FileControlVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "文件管制管理")
@RestController
@RequestMapping("/api/file-control")
public class FileControlController {

    @Autowired
    private FileControlService fileControlService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result getPage(
            @ApiParam("当前页") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("文件编号") @RequestParam(required = false) String fileNumber) {
        return Result.ok(fileControlService.getPage(current, size, fileNumber));
    }

    @ApiOperation("获取详情")
    @GetMapping("/{id}")
    public Result getDetail(@PathVariable Long id) {
        return Result.ok(fileControlService.getDetail(id));
    }

    @ApiOperation("保存或更新")
    @PostMapping("/save")
    public Result saveOrUpdate(@RequestBody List<FileControlVO> vo) {
        fileControlService.saveOrUpdateBatchTransactional(vo);
        return Result.ok();
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public Result removeBatch(@RequestBody Long[] ids) {
        fileControlService.removeBatch(ids);
        return Result.ok();
    }
}